<template>
<div>
      <h3>{{msg}}</h3><br/>
        <el-button type="text" @click="addDialog()"><u>添加</u></el-button>
    <el-dialog title="添加页面" :visible.sync="dialogVisible" width="30%">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="角色名称">
          <el-input v-model="form.name"  placeholder="请输入角色名称"></el-input>
        </el-form-item>
        <el-form-item label="备注">
            <el-input
                type="textarea"
                :rows="5"
                placeholder="请输入内容"
                v-model="form.remarks">
        </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button @click="add()"><i class="el-icon-plus">添加</i></el-button>
      </span>
    </el-dialog>
    <router-view></router-view>
<el-main>
          
        角色名称:
  <el-input v-model="roleName" placeholder="请输入用户名" style="width:240px"></el-input>
  <el-button type="primary" @click="requestData()">搜索</el-button>
  <!-- <el-button type="text" @click="addDialog()"><u>添加</u></el-button> -->
     <el-table :data="tableData" style="width: 100%" height="250"> 
    <el-table-column fixed prop="id" label="编号" width="150">
    </el-table-column>
     <el-table-column prop="name" label="拥有角色" width="120">
    </el-table-column>
    <el-table-column prop="remarks" label="备注" width="300">
    </el-table-column>
    <el-table-column prop="bz" label="权限菜单设置" width="300">
        <template slot-scope="scope">
        <el-button size="small" type="text" @click="handleDelete(scope.row)">删除</el-button>
         <el-button size="small" type="text" @click="handleUpdate(scope.row)">修改</el-button>
      </template>
    </el-table-column>
  </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  
  </el-main>
  </div>
</template>

<script>

export default {
    data() {
        return {
           msg: '角色管理',
             tableData:[],
              currentPage:1,
             dialogVisible:false,
             parameter:'',
             roleName:'',
            currentPage:1,
             pageSizes:[5, 10, 20, 30],
             pageSize:5,
             total:10,
             page:{},
             form: {
             name: '',
             remarks:''
             },
        }
    },mounted(){
       this.requestData();

    },methods:{
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
         this.requestData();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.currentPage = val;
        this.requestData();
      },
        requestData(){
          var data = new FormData();
          data.append('name',this.roleName);
          data.append('pageNum',this.currentPage);
          data.append('pageSize',this.pageSize);
          var api = "http://localhost:8089/admin/role/listAlls"; 
            this.$http.post(api,data).then(response =>{
                 console.log(response);
                 this.tableData = response.body.tableData;
                 this.total =  response.body.total;
                
            }
             );   
        },
        handleDelete(row){
            // alert("ff");
            if(confirm("确定删除吗？")){
                  console.log(row);
             //alert(row.id)
             var formData = new FormData();
             formData.append('id',row.id);
             var api="http://localhost:8089/admin/role/deletea";
             this.$http.post(api,formData).then(function(data){
               if(data.body.code=='10000'){
                   this.requestData();
               }
             alert(data.body.msg);
       })
            }  
        },handleUpdate(row){
            this.$router.push({name:'/UserUpd',params:{id:row.id}});
        },addDialog(){
            this.dialogVisible = true;
            for(let key in this.form){
            this.form[key]  = '';
         }
        },
      add(){
        this.dialogVisible = true;
            var name=this.form.name;
            var remarks=this.form.remarks;
            var formDate =new FormData();
            formDate.append('name',name);
            formDate.append('remarks',remarks);
            var api='http://localhost:8089/admin/role/savea';
            this.$http.post(api,formDate).then(function(date){
            if(date.body.code=='10000'){
              window.location.href="http://localhost:8080/#/list";
            }
            alert(date.body.msg);
            this.dialogVisible = false;
         })
           }
    }
}
</script>

